package com.git.hui.yinshua.api.model;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.git.hui.yinshua.api.model.user.UserBo;
import lombok.Data;


/**
 * @author YiHui
 * @date 2024/6/7
 */
public class ReqInfoContext {

    private static ThreadLocal<ReqInfo> contexts = new TransmittableThreadLocal<>();

    public static void addReqInfo(ReqInfo reqInfo) {
        contexts.set(reqInfo);
    }

    public static void clear() {
        contexts.remove();
    }

    public static ReqInfo getReqInfo() {
        return contexts.get();
    }

    @Data
    public static class ReqInfo {
        /**
         * appKey
         */
        private String appKey;
        /**
         * 访问的域名
         */
        private String host;
        /**
         * 访问路径
         */
        private String path;
        /**
         * 客户端ip
         */
        private String clientIp;
        /**
         * referer
         */
        private String referer;
        /**
         * post 表单参数
         */
        private String payload;
        /**
         * 设备信息
         */
        private String userAgent;

        /**
         * session
         */
        private String sessionId;
        /**
         * 用户id
         */
        private Integer userId;
        /**
         * 登录用户
         */
        private UserBo user;
    }
}
